package com.lei2j.state;

/**
 * Created by lei2j on 2019/2/4.
 */
public class SoldState implements State {

    private GumballaMachine gumballaMachine;

    public SoldState(GumballaMachine gumballaMachine) {
        this.gumballaMachine = gumballaMachine;
    }

    @Override
    public void dispense() {
        gumballaMachine.releaseBall();
        if(gumballaMachine.getCount()>0){
            gumballaMachine.setState(gumballaMachine.getNoQuarterState());
        }else{
            gumballaMachine.setState(gumballaMachine.getSoldoutState());
        }
    }
}
